<template>
  <div class="integralmall">
    <div class="outmain ba_f heighthv pad_20 bor_rad5">
      <div class="shuju_title mar_b20">
        <div class="shuju_title_text">
          <span>积分商城设置</span>
        </div>
      </div>
      <div class="mar_t20 flex-bet flex-y-top">
        <el-form ref="form" :model="form" label-width="180px">
          <el-form-item label="短信提醒">
            <el-tooltip :content="form.smsOpen==1?'开启':'关闭'" placement="top">
              <el-switch v-model="form.smsOpen" active-value="1" inactive-value="2"></el-switch>
            </el-tooltip>
            <div class="mar_t10" v-show="form.smsOpen=='1'">
              <el-input v-model="form.tel" placeholder="请输入电话号码"></el-input>
            </div>
          </el-form-item>
          <el-form-item label="订单打印">
            <el-tooltip :content="form.printOpen==1?'开启':'关闭'" placement="top">
              <el-switch v-model="form.printOpen" active-value="1" inactive-value="2"></el-switch>
            </el-tooltip>
            <!--                            <div class="mar_t10"  v-show="form.printOpen=='1'">-->
            <!--                                请设置打印机参数<a class="subjectcolor2 mar_l10"  @click="printSet()">打印机设置</a>-->
            <!--                            </div>-->
          </el-form-item>
          <div class="shuju_title mar_b20">
            <div class="shuju_title_text">
              <span>积分规则</span>
            </div>
          </div>
          <el-form-item label="规则协议">
            <baidu-ueditor :content="form.details" @ueditor="getUeditor"></baidu-ueditor>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="mar_t20 ba_f pad_20 t_c">
      <el-button type="primary" @click="submitForm">确认</el-button>
    </div>
    <!--        <edit ref="edit"></edit>-->
  </div>
</template>
<script>
import { getConfig, postConfig } from '@/api/setup';
import { changeDate } from '@/utils/index';
import baiduUeditor from '@/plugins/baidu-ueditor';
// import Edit from "./components/integralprint";

export default {
  // components: {Edit},
  components: { baiduUeditor },
  created() {
    this.bus.$emit('loading', true);
    this.init();
  },
  data() {
    return {
      form: {
        tel: '',
        smsOpen: '2',
        printOpen: '2',
        details: ''
      }
    };
  },
  methods: {
    async init() {
      const { data } = await getConfig({ ident: 'integralShop' });
      this.form2 = this.form;
      this.form = Object.assign(this.form2, data);
      this.bus.$emit('loading', false);
    },
    getUeditor(content) {
      this.form.details = content;
    },
    enter(i = 0) {
      this.$refs['imgicon' + i].style.display = 'none';
    },
    leave(i = 0) {
      this.$refs['imgicon' + i].style.display = 'inline-block';
    },
    test(i = 0) {
      console.log(this.$refs, i);
      this.$refs['img' + i].dialogVisible = true;
    },
    imgadd1(url) {
      this.form.icon = url.str;
    },
    deleteMultiImage(item, index, type) {
      //typem没传是单图multigraph多图；index上传图片组件排序
      Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
          this.splice(index, 1);
        }
      };
      if (type == 'multigraph') {
        switch (index) {
          case 2:
            this.form2.environment.remove(item);
            break;
        }
      } else {
        switch (index) {
          case 1:
            this.form.icon = '';
            break;
        }
      }
    },
    printSet(row) {
      if (row.id) {
        this.$refs['edit'].showEdit(row);
      } else {
        this.$refs['edit'].showEdit();
      }
    },
    async submitForm() {
      this.$refs['form'].validate(async (valid) => {
        if (valid) {
          this.form.ident = 'integralShop';
          this.form.identName = '积分商城设置';
          const { msg } = await postConfig(this.form);
          this.$baseMessage(msg, 'success');
          this.init();
        } else {
          return false;
        }
      });
    }
  }
};
</script>
<style lang="scss">
.integralmall {
  .time_item .el-input {
    width: 180px;
  }
}
</style>
